﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for PrintDischargeBallot.xaml
    /// </summary>
    public partial class PrintDischargeBallot : UserControl
    {
        long idComplaint;
        Person person = new Person();
        Actor actor = new Actor();
        Employee employee = new Employee();
        Complaint complaint = new Complaint();
        DirectAction direct = new DirectAction();
        Model.EntityModel.InterveningPolice police = new InterveningPolice();

        public PrintDischargeBallot(long idComplaint)
        {
            InitializeComponent();
            this.idComplaint = idComplaint;
            try
            {
                ChargeComplaintFields();
                ChargeDirectActionFields();
                ChargeInterveningPoliceFields();
                ChargeEmployeeFields();
                ChargeAggressorFields();
            }
            catch (Exception e)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Error al generar papeleta de descargo", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void ChargeComplaintFields()
        {
            complaint = DataAccess.ComplaintDataAccess.GetComplaintById(idComplaint);
            LblDate.Content = complaint.RegistrationDate.ToString();
            lblCaseNumber.Content = idComplaint;
        }

        private void ChargeDirectActionFields()
        {
            direct = DataAccess.DirectActionDataAccess.GetDirectActionById(Convert.ToInt64(complaint.IdDirectAction));
            LblTime.Content = direct.IncidentTime.ToString();
        }

        private void ChargeInterveningPoliceFields()
        {
            long ci = Convert.ToInt64(direct.CIInterveningPolice);
            police = DataAccess.InterveningPoliceDataAccess.GetPoliceByCi(ci);
            LblOfficialName.Content = police.Rank.ToString() + " " + police.Name.ToString() + " " + police.PaternalName.ToString() + " " + police.MaternalName.ToString();
            LblOfficeStation.Content = police.PoliceStation.ToString();
            LblOfficeCI.Content = police.CI.ToString();
        }

        private void ChargeEmployeeFields()
        {
            employee = DataAccess.EmployeeDataAccess.GetEmployeeByCi(Convert.ToInt64(direct.CIEmployee));
            LblPoliceName.Content = employee.Rank.ToString() + " " + employee.Name.ToString() + " " + employee.PaternalName.ToString() + " " + employee.MaternalName.ToString();
        }

        private void ChargeAggressorFields()
        {
            actor = DataAccess.PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Agresor", idComplaint);
            person = DataAccess.PersonAndActorDataAccess.GetPersonById(actor.IdPerson.ToString());
            LblAggressorName.Content = person.Name.ToString() + " " + person.PaternalName.ToString() + " " + person.MaternalName.ToString();
        }
    }
}
